package com.lzy.wzy.mapper;

import com.lzy.wzy.model.*;
import com.lzy.wzy.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

@Mapper
public interface WorkMapper {

    //录入生产工单需求
    Integer addWorkOrder(WorkOrderBean workOrderBean);

    //根据工单号查看工单信息
    ModifyWorkOrderBean queryWorkOrderInfoByNO(String workOrderNumber);

    //查询此工单是否存在
    Integer getSingleWorkOrder(String workOrderNumber);

    //    获取工单生产日期
    String getWorkOrderProductionDate(String workOrderNumber);

    //根据工单id和当前时间查询工单
    Integer queryWorkOrderInfoByIdAndCreateTime(Map<String, Object> map);

    //查询所有工单
    List<WorkOrderVo> queryAllWorkOrder(String status);

    //根据工单号查看工单修改记录
    List<ModifyRecordBean> queryModifyRecordInfoByNO(String workOrderNumber);

    //查询工单当天最后一条记录
    String getThatDayLastWorkOrder(@Param("currentTime") String currentTime, @Param("workType") String workType);

    //根据工单号修改工单
    Integer modifyWorkOrder(ModifyWorkOrderBean workOrderBean);

    //文本工单搜索
    List<WorkOrderVo> search(String searchValue);

    //历史工单搜索
    List<WorkOrderVo> searchHistoricalTickets(String historicalTime);

    Integer batchUpdateWorkOrder(@Param("workOrderBeans") List<ModifyWorkOrderBean> workOrderBeans);

    //记录工单修改信息
    Integer saveModifyInfo(ModifyRecordBean modifyRecordBean);

    //添加多条修改信息
    Integer batchInsertMultipleModifyInfo(@Param("map") Map<String, String> map, @Param("modifyTime") LocalDateTime modifyTime, @Param("modifier") String modifier, @Param("type") int type, @Param("templateId") int templateId);

    //通过工单号获取多条工单信息
    List<ModifyWorkOrderBean> getMultipleWorkOrderInfo(@Param("workOrderNumbers") List<String> workOrderNumbers);

    //获取多条工单状态
    List<String> getMultipleWorkOrderStatus(@Param("workOrderNumbers") List<String> workOrderNumbers);

    //获取所有下达工单
    List<Map<String, String>> getAllReleasedWorkOrdersNumber(String status);

    //更新工单状态
    Integer updateWorkOrderStatus(@Param("status") String status, @Param("workOrderNumber") String workOrderNumber);
    Integer updateWorkOrderStatusAndProductDate(@Param("productionDate") LocalDate productionDate,@Param("status") String status,@Param("oldStatus")String oldStatus, @Param("workOrderNumber") String workOrderNumber);
    //更新状态和结案时间
    void updateStatusAndClosingTime(@Param("status") String status, @Param("expectedStatus")String expectedStatus, @Param("closingDate") LocalDate closingDate, @Param("lastClosingTime") LocalDate lastClosingTime, @Param("workOrderNumber") String workOrderNumber);

    //更新状态和完工时间
    void updateStatusAndCompletionDate(@Param("status") String status,@Param("expectedStatus")String expectedStatus, @Param("completionDate") LocalDate completionDate, @Param("workOrderNumber") String workOrderNumber);

    //更新结案时间
    void updateClosingTime(@Param("closingDate") LocalDate closingDate, @Param("workOrderNumber") String workOrderNumber);

    void updateStatusClosingTime(@Param("closingDate") LocalDate closingDate,@Param("expectedStatus")String expectedStatus, @Param("workOrderNumber") String workOrderNumber);

    //获取结案时间
    LocalDate getClosingTime(String workOrderNumber);

    //获取上一次结案时间
    LocalDate getLastClosingTime(String workOrderNumber);

    //获取结案和反结案时间
    CloseAndAntiClose getClosingAndAntiClosingTime(String workOrderNumber);

    //保存反结案时间
    void saveAntiClosingTime(@Param("time") LocalDate time, @Param("workOrderNumber") String workOrderNumber);

    //更新工单标识符和状态
    Integer updateWorkOrderIdentifierAndStatus(@Param("identifier") int identifier, @Param("status") String status, @Param("workOrderNumber") String workOrderNumber);

    //更新工单标识符
    Integer updateWorkOrderIdentifier(@Param("identifier") int identifier,@Param("workOrderNumber") String workOrderNumber);
    //获取工单状态
    String getWorkOrderStatus(String workOrderNumber);

    //获取标识符和状态
    IdentifierStatus getIdentifierAndStatus(String workOrderNumber);

    //获取所有返修工单
    List<String> getAllReworkOrder(@Param("status") String status, @Param("workType") String workType);

    //获取所有工单号
    List<String> getAllWorkOrderNumber();

    //获取工单部分信息
    WorkOrderPartInfo obtainPartOfWorkOrderInformation(String workOrderNumber);

    //获取工单表头信息
    LinkedHashMap<String, Object> getWorkOrderHeaderInformation(String workOrderNumber);

    //保存实际开工日期
    void saveProductDate(@Param("productionDate") LocalDate productionDate, @Param("workOrderNumber") String workOrderNumber);

    //通过工单状态获取工单号
    List<String> getAllWorkOrderNumbersByStatus(String status);

    //获取工单软件版本
    String getSoftVersionByNumber(String workOrderNumber);

    //更新软件版本
    void updateSoftVersion(String softVersion, String workOrderNumber);

    //通过工单状态查询工单
    List<WorkOrderVo> getWorkOrderByStatus(String status);

    //获取工单总数
    List<String> getAllWorkOrderStatus();

    //获取携带反结案标识的完工工单
    List<String> getWorkOrderByIdentifier(@Param("identifier") int identifier, @Param("status") String status);

    //获取工单所有待处理异常信息
    List<PendingExceptionInfoVo> getPendingExceptionInfo(@Param("workOrderNumber") String workOrderNumber, @Param("status") String status);

    //获取所有待确认和待执行异常信息
    List<ConfirmedExceptionInfoVo> getAllExceptionInfoByStatus(@Param("workOrderNumber") String workOrderNumber, @Param("status") String status);

    //获取工单异常信息状态
    String getStatusByExceptionId(int id);

    //保存处理方案
    Integer saveTreatmentPlan(@Param("treatmentPlan") String treatmentPlan, @Param("id") int id, @Param("userId") String userId, @Param("closeDate") LocalDateTime closeDate, @Param("status") String status, @Param("filePath") String filePath);

    //保存执行人信息
    Integer saveExecutorInfo(@Param("userId") String userId, @Param("executeTime") LocalDateTime executeTime, @Param("exeResult") String exeResult, @Param("status") String status, @Param("id") int id);

    //保存确认人信息
    Integer saveConfirmorInformation(@Param("userId") String userId, @Param("confirmorDate") LocalDateTime confirmorDate, @Param("status") String status, @Param("id") int id);

    //获取已完成的历史异常信息
    List<HistoryExceptionVo> getThisWorkOrderAllExceptionInfo(@Param("workOrderNumber") String workOrderNumber, @Param("status") String status);

    //获取为完成的异常个数
    Integer getThisWorkOrderExceptionCount(@Param("workOrderNumber") String workOrderNumber, @Param("status") String status);

    //获取最新的一条异常工单状态
    String getExceptionWorkOrderStatus(String workOrderNumber);

    //异常信息查询
    List<HistoryExceptionVo> getExceptionInfoByCondition(String searchValue);

    //通过处理状态获取异常表工单号
    List<String> getWorkOrderNumberByProcessingStatus(String status);

    List<String> getWorkOrderNumberByProcessingStatusAndIdentifier(@Param("status") String status, @Param("identifier") int identifier);

    //通过id查询异常上报表转让标识符
    int getTransferIdentifierById(int id);

    void updateTransferIdentifierByIdAndStatus(@Param("identifier") int identifier, @Param("id") int id,@Param("status")String status);

    //更新完结解释
    void updateCompletionTime(@Param("endTime") LocalDate endTime, @Param("workOrderNumber") String workOrderNumber);

    //获取工单标识
    Integer getIdentifierByNumber(String workOrderNumber);

    //删除工单
    Integer deleteWorkOrder(String workOrderNumber);

    //获取完工时间
    LocalDate getCompletionTimeByNumber(String workOrderNumber);

    LocalDate getClosingTimeByNumber(String workOrderNumber);

    //通过产品编码获取工单
    List<String> getWorkOrderByCode(String code);

    //通过产品编码获取生产数量
    Integer getProductQuantityByProductCode(String productCode);

    //通过工单号获取生产数量
    Integer getProductQuantityByWorkOrderNumber(String workOrderNumber);

    //获取记录表模板记录最早一条记录
    LocalDate getFirstRecord();

    //获取记录表模板记录最晚一条记录
    LocalDate getLastRecord();

    //获取所有在用产品编码
    List<String> getAllProductCode();

    //获取近期三天操作
    List<BulletinBean> getBulletin();

    //根据工单号生产修改删除记录
    void deleteModifyRecordByNumber(String workOrderNumber);

    //根据工单号生产删除异常上报记录
    void deleteReportExceptionInfoByNumber(String workOrderNumber);


    LocalDate getWorkOrderCreateTime(String workOrderNumber);

    void saveProductStat(@Param("list") List<ProductStatBean> list);


    ProductStatBean getProductStat(@Param("code") String code, @Param("time") LocalDate time);

    ProductReportStatBean getReportStatData(@Param("productCode") String productCode,@Param("workOrderNumber")String workOrderNumber,@Param("statTime")String statTime,@Param("statType")int statType);

    //获取异常处理附件路径
    String getDixPathById(int id);
    //获取异常信息附件路径
    String getReportFilePathById(int id);

    //获取生产总量
    Integer getTotalQuantity();

    //获取此编码最早使用的时间
    LocalDate getTheEarliestCreateTime(String productCode);

    //获取审批人签字
    List<ApproveSignVo> getApproveSign(String workOrderNumber);

    //获取所有项目号
    List<KeyValueVo> getAllProjectNumber();

    //获取项目创建时间
    LocalDate getProjectDate(String projectNumber);

    //通过项目号查询项目部分信息
    String queryProjectName(String projectNumber);

    //保存项目信息
    Integer saveProjectInfo(OutOfHoursStatisticsBean outOfHoursStatisticsBean);
    //获取所有项目工时信息
    List<OutOfHoursStatisticsVo> getAllProjectHoursInfo();
    //更新项目信息
    Integer updateProjectInfo(OutOfHoursStatisticsBean outOfHoursStatisticsBean);

    //保存管理人员工时
    Integer saveAttTime(ProductionManagementHoursBean productionManagementHoursBean);

    //更新管理工时信息
    Integer updateAttTimeInfo(ProductionManagementHoursBean productionManagementHoursBean);

    //获取生产工时信息
    List<WorkingHoursVo> getAllProductionHoursInfo();

    //保存生产工时信息
    Integer saveProductionHoursInfo(WorkingHoursBean workingHoursBean);

    //更新生产工时信息
    Integer updateProductionHoursInfo(WorkingHoursPartBean workingHoursPartBean);

    //查询此工单今天是否已经提交过工时
    Integer checkExistProductionHours(@Param("workOrderNumber") String workOrderNumber,@Param("recordDate") LocalDate recordDate,@Param("name")String name);

    //按工单号查询生产工时
    HoursStaticsVo queryProductHoursByWorkOrderNumber(int year);

    //按月查询生产工时
    HoursStaticsVo queryProductHoursByMonth(@Param("year") int year,@Param("month") int month);
    //按月统计工单工时
    List<StatHoursVo> statWorkOrderHoursByMonth(@Param("year") int year,@Param("month") int month);

    //按年统计工单工时
    List<StatHoursVo> statWorkOrderHoursByYear(int year);
    //按工单统计年工单工时
    List<StatHoursVo> statYearWorkOrderHoursByNumber(@Param("workOrderNumber")String workOrderNumber,@Param("year") int year);


    //<!--    按工单统计月工单工时-->
    List<StatHoursVo> statMonthWorkOrderHoursByNumber(@Param("workOrderNumber")String workOrderNumber ,@Param("year") int year,@Param("month") int month);
    //通过工单号获取生产工时信息
    List<WorkingHoursVo> getProductionHoursInfoByNumber(String workOrderNumber);
    //查询项目是否存在
    Integer getProjectCountByNumber(String projectNumber);
    //通过项目编号或项目名称查询项目信息
    List<OutOfHoursStatisticsVo> getProjectHoursInfoByNumberOrName(String searchValue);

    //按年统计项目表工时信息
    List<StatHoursVo> statProjectWorkingHoursByYear(int year);

    //按月统计项目表工时信息
    List<StatHoursVo> statProjectWorkingHoursByMonth(@Param("year") int year,@Param("month") int month);
    //根据项目编码统计项目月工时
    List<StatHoursVo> statProjectMonthWorkingHoursByProjectNumber(@Param("projectNumber") String projectNumber,@Param("year") int year,@Param("month") int month);
    //根据项目编码统计项目月工时
    List<StatHoursVo> statProjectYearWorkingHoursByProjectNumber(@Param("projectNumber")String projectNumber,@Param("year") int year);


    //检查改用户当天是否填写此项目管理工时
    Integer queryManageWorkingHoursCount(@Param("jobNumber")String jobNumber,@Param("projectNumber")String projectNumber,@Param("recordDate")LocalDate recordDate);

    //通过项目编号查询项目信息
    //OutOfHoursStatisticsVo getProjectHoursInfoByProjectNumber(String projectNumber);

    //查询项目是否存在
    Integer queryProjectExist(@Param("projectNumber")String projectNumber,@Param("projectDate") LocalDate projectDate,@Param("userId")String userId);
    //新增项目
    Integer addProject(@Param("projectNumber")String projectNumber,@Param("projectName")String projectName,@Param("projectDate")LocalDate projectDate);

    //删除项目
    Integer delProject(String projectNumber);

    //查询月管理工时
    List<StatHoursVo>  getManageMonthWorkingTime(@Param("jobNumber")String jobNumber,@Param("year")int year,@Param("month")int month);

    //查询年管理工时
    List<StatHoursVo>  getManageYearWorkingTime(@Param("jobNumber")String jobNumber,@Param("year")int year);

    //通过项目号查询年管理工时
    List<StatHoursVo>  getManageYearWorkingTimeByProjectNumber(@Param("jobNumber")String jobNumber,@Param("year")int year,@Param("projectNumber")String projectNumber);

    //通过项目号查询月管理工时
    List<StatHoursVo>  getManageMonthWorkingTimeByProjectNumber(@Param("jobNumber")String jobNumber,@Param("year")int year,@Param("month")int month,@Param("projectNumber")String projectNumber);

    //查询所有人月管理工时
    List<StatHoursVo> getAllThePeopleManageMonthWorkingTime(@Param("year")int year,@Param("month")int month);

    //查询年管理工时
    List<StatHoursVo> getAllThePeopleManageYearWorkingTime(int year);

    //通过项目号查询所有人月管理工时
    List<StatHoursVo> getAllThePeopleManageMonthWorkingTimeByProjectNumber(@Param("year")int year,@Param("month")int month,@Param("projectNumber")String projectNumber);

    //通过项目号查询所有人年管理工时
    List<StatHoursVo> getAllThePeopleManageYearWorkingTimeByProjectNumber(@Param("year")int year,@Param("projectNumber")String projectNumber);

    //个人项目管理工时年报导出查询
    List<ManageTimeVo> getAllThePeopleYearManageWorkingTimeReport(int year);

    //个人项目管理工时年报导出查询
    List<ManageTimeVo> getAllThePeopleMonthManageWorkingTimeReport(@Param("year") int year,@Param("month") int month);

    //个人所有项目管理工时月报查询
    List<ManageTimeVo> getPersonalMonthManageWorkingTime(@Param("jobNumber")String jobNumber,@Param("year") int year,@Param("month") int month);

    //个人所有项目管理工时年报查询
    List<ManageTimeVo> getPersonalYearManageWorkingTime(@Param("jobNumber")String jobNumber,@Param("year") int year);

    //通过工号查询个人管理工时信息
    List<ManageWorkingTimeVo> getPersonalManageWorkingHoursInfoByJobNumber(String jobNumber);

    //通过时间查询个人管理工时信息
    List<ManageWorkingTimeVo> getPersonalManageWorkingHoursInfoByTime(@Param("year") int year,@Param("month") int month,@Param("jobNumber")String jobNumber);

    //通过工号和项目编号查询个人管理工时信息
    List<ManageWorkingTimeVo> getPersonalManageWorkingHoursInfoByJobNumberAndPNumber(@Param("jobNumber") String jobNumber,@Param("projectNumber") String projectNumber);

    //获取所有已绑定模板的返修工单
    List<String> getAllIsBindingReworkOrderNumber();

    //查询本月生产工时信息
    List<WorkingHoursVo> queryTheProductionTimeOfThisMonth(@Param("year")int year,@Param("month") int month);

    //查询本年度生产工时信息
    List<WorkingHoursVo> queryTheProductionTimeOfThisYear(int year);

    //查询本月项目工时信息
    List<OutOfHoursStatisticsVo> queryTheProjectTimeOfThisMonth(@Param("year")int year,@Param("month") int month);

    //查询本年度生产工时信息
    List<OutOfHoursStatisticsVo> queryTheProjectTimeOfThisYear(int year);


    //通过工号和年份查询个人管理工时信息
    List<ManageWorkingTimeVo> getPersonalAnnualManageWorkingHoursInfo(@Param("year") int year,@Param("jobNumber")String jobNumber);

    //通过工号和年月查询个人管理工时信息
    List<ManageWorkingTimeVo> getPersonalMonthlyManageWorkingHoursInfo(@Param("year") int year,@Param("month") int month,@Param("jobNumber")String jobNumber);


    //根据工单号查询产品型号
    String getProductNumberByWorkOrderNumber(String workOrderNumber);


    //删除生产工时
    Integer delProductionHoursById(int id);

    //删除非生产工时
    Integer delProjectHoursById(int id);

    //删除管理工时
    Integer delManagementHoursById(int id);

    //根据产品编码查询工单
    List<String> getWorksByProductCode(String productCode);

    //模糊查询工单号
    List<TicketVo> searchWorkOrderNumber(String val);

    //模糊查询产品编码
    List<TicketVo> searchProductCode(String val);

    //模糊查询订单号
    List<TicketVo> searchOrderNumber(String val);

    //更新工单状态
    void updateTicketStatus(@Param("workOrderNumber")String workOrderNumber,@Param("futureStatus")String futureStatus,@Param("expectedStatus")String expectedStatus);
}
